/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-29 22:12:59
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-30 15:13:00
 * @FilePath: \electrion\main.js
 * @Description: 主进程文件 * 
 */
const {app,BrowserWindow,ipcMain} = require('electron');
const fs = require('fs');
const path = require('path')

function writeFile (event,value,){
    console.log('触发函数',event,value)
    fs.writeFileSync('D:/01Flies/前端学习/hello.txt',value)
}
//读取文件
function readFile (){
let result = fs.readFileSync('D:/01Flies/前端学习/hello.txt')
return result.toString()
    
}
//创建窗口
function createWindow() {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
        autoHideMenuBar: true, //隐藏菜单
        alwaysOnTop: true, //层级置顶
        webPreferences:{
            preload:path.resolve(__dirname,'./preload.js')
        }
    })
    //触发 save-file 事件并指定回调函数 writeFile
    ipcMain.on('save-file',writeFile)
    ipcMain.handle('read-file',readFile)






    // win.loadFile('http://www.atguigu.com')
    



    win.loadFile('./pages/index.html')
}
//应用准备好了的时候
app.on('ready', () => {
    createWindow()
})
//window 关闭一个应用的所有窗口后让它退出
app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})
//macOS  应用被激活事件
app.on('activate', () => {
    //当前窗口数量如果是0 //创建一个chuagn
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
//  process 进程通信

// console.log(process.versions.chrome)
// console.log(process.versions.electron)
// console.log(process.versions.node)
// console.log(process.versions.npm)